package master.common.utils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author <a href="mailto:jfox.young@gmail.com">Young Yang</a>
 */
/*
@Controller
@RequestMapping("/fileupload")
public class FileUploadController {

	@RequestMapping(method=RequestMethod.GET)
	public void fileUploadForm(@RequestHeader(value="X-Requested-With", required=false) String requestedWith, Model model) {
		model.addAttribute("ajaxRequest", AjaxUtil.isAjaxRequest(requestedWith));
	}

	@RequestMapping(method=RequestMethod.POST)
	public void processUpload(@RequestParam MultipartFile file, HttpServletRequest request, Model model) throws IOException {
		String message = "File '" + file.getOriginalFilename() + "' uploaded successfully";
		// prepare model for rendering success message in this request
		model.addAttribute("message", new Message(MessageType.success, message));
		model.addAttribute("ajaxRequest", AjaxUtil.isAjaxUploadRequest(request));
	}

}
*/
public class AjaxUtil {

    private AjaxUtil() {}

    public static boolean isAjaxRequest(String requestedWith) {
        return requestedWith != null ? "XMLHttpRequest".equals(requestedWith) : false;
    }

    public static boolean isAjaxUploadRequest(HttpServletRequest request) {
        return request.getParameter("ajaxUpload") != null;
    }

}
